#ifndef _WIDGETS_H_
#define _WIDGETS_H_

#include "gui.h"

////////////////////////////////////////////////////////////////////////////////

enum ButtonEvent
{
  BUTTON_PRESSED
};

class Button: public Widget
{
  public:
  Button(const char* text);
  
  const char* getTypeName() const {return "Button";};
  
  bool handleMousePress(const MousePressEvent& event);
  bool handleMouseRelease(const MousePressEvent& event);
  
  void draw();
  
  private:
  String _text;
  bool _down;
};

////////////////////////////////////////////////////////////////////////////////

enum SpinBoxEvent
{
  SPIN_BOX_VALUE
};

class SpinBox: public Widget
{
  public:
  SpinBox(int value, int min, int max);
  
  const char* getTypeName() const {return "SpinBox";}
  
  int value() const {return _value;}
  
  void setMin(int min);
  void setMax(int max);
  
  bool handleMousePress(const MousePressEvent& event);
  bool handleMouseRelease(const MousePressEvent& event);
  
  void draw();
  
  private:
  void onSetDim();
  
  int _value;
  int _min;
  int _max;
  bool _up_button_down;
  bool _down_button_down;
  Rect _value_rect;
  Rect _up_rect;
  Rect _down_rect;
};

////////////////////////////////////////////////////////////////////////////////

#define TEXT_FIELD_MAX_CHARS 256

class TextField: public Widget
{
  public:
  TextField();
  
  const char* getTypeName() const {return "TextField";}
  
  const char* text() const {return _text;}
  void setEnabled(bool enabled);
  
  bool handleKeyDown(const GUIKeyDownEvent* event);
  
  void draw();
  
  private:
  bool _enabled;
  int _length;
  char _text[TEXT_FIELD_MAX_CHARS];
};

////////////////////////////////////////////////////////////////////////////////

class ViewportRenderer
{
  public:
  virtual ~ViewportRenderer() {}
  
  virtual void onChangeDim(const Dimension& dim) = 0;
  virtual void draw() = 0;
};

class Viewport: public Widget
{
  public:
  Viewport(ViewportRenderer* renderer);
  
  const char* getTypeName() const {return "Viewport";}
  
  void draw();
  
  private:
  void onSetDim();
  
  ViewportRenderer* _renderer;
};

class Panel: public Widget
{
  public:
  const char* getTypeName() const {return "Panel";}
  
  void add(Widget* widget, int x, int y);
  
  Widget* getWidget(const Point& pos);
  
  void handleEvent(GUIEvent* event) {}
  
  void doLayout();
  void draw();
  
  private:
  List<Widget*> _children;
};

class Column: public Widget
{
  public:
  Column();
  
  const char* getTypeName() const {return "Column";};
  
  void setSpacing(int spacing);
  
  void add(Widget* widget);
  
  Widget* getWidget(const Point& pos);
  
  void handleEvent(GUIEvent* event) {}
  
  void doLayout();
  void draw();
  
  protected:
  void onSetDim();
  
  private:
  int _spacing;
  List<Widget*> _children;
};

class Background: public Widget
{
  public:
  Background();
  
  const char* getTypeName() const {return "Background";};
  
  void setColour(Colour colour);
  
  void handleEvent(GUIEvent* event) {}
  
  void draw();
  
  private:
  Colour _colour;
};

#endif
